#include "Application.h"

System::Application::Application( int argc, char **argv )
	: commandSize( argc ), commandLine( new wchar_t*[argc + 1] )
{
	for ( int i = 0; i < commandSize; ++i )
		mbstowcs( commandLine[i] = new wchar_t[mbstowcs( NULL, argv[i], MAXIMUM_COMMANDLINE ) + 1], argv[i], MAXIMUM_COMMANDLINE );

	commandLine[commandSize] = NULL;
}

System::Application::Application()
	: commandSize( 0 ), commandLine( NULL )
{
#ifdef _WIN32
	PWSTR *commandTemp = CommandLineToArgvW( GetCommandLine(), &commandSize );

	if ( commandTemp != NULL )
	{
		commandLine = new PWSTR[commandSize + 1];

		for (int i = 0; i < commandSize; ++i)
			wcscpy( commandLine[i] = new WCHAR[wcslen( commandTemp[i] )], commandTemp[i] );

		commandLine[commandSize] = NULL;
	}
	else
	{
		MessageBox( NULL, L"CommandLineToArgvW Failed", L"Warning", MB_ICONWARNING | MB_OK );
		commandSize = 0;
	}

	if ( commandTemp != NULL )
		LocalFree( commandTemp );
#endif
}

System::Application::~Application()
{
	if ( commandLine != NULL )
	{
		for ( int i = 0; i < commandSize; ++i )
			delete[] commandLine[i];

		delete[] commandLine;
	}
}
